home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / EX52.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  1KB  |  37 lines

  1. TITLE  Delete from Unordered List (EX52.ASM)
  2.           PAGE      ,132
  3. OUR_CODE  SEGMENT   PARA 'CODE'
  4.       PUBLIC    DEL_UL
  5. DEL_UL    PROC      FAR
  6.           ASSUME    CS:OUR_CODE
  7.       CLD                     ;Make DF=0, to scan forward
  8.       PUSH        BX             ;Save scratch register BX
  9.       PUSH        DI             ; and starting address
  10.       MOV        CX,ES:[DI]         ;Fetch element count
  11.       ADD        DI,2         ;Make DI point to 1st data el.
  12. REPNE      SCASW                     ;Value in the list?
  13.       JE        DELETE             ; If so, go delete it.
  14.       POP        DI             ; Otherwise, restore registers
  15.       POP        BX
  16.       RET                 ;  and exit.
  17. ;
  18. ;  The following instructions delete an element from the list,
  19. ;  as follows:
  20. ;    (1)  If the element lies at the end of the list,
  21. ;         delete it by decreasing the element count by 1.
  22. ;    (2)  Otherwise, delete the element by moving all
  23. ;         subsequent elements up by one position.
  24. ;
  25. DELETE:   JCXZ        DEC_CNT         ;If (CX) = 0, delete last el.
  26. NEXT_EL:  MOV        BX,ES:[DI]         ;Move one element up in list
  27.       MOV        ES:[DI-2],BX
  28.       ADD        DI,2         ;Point to next element
  29.       LOOP        NEXT_EL          ;Repeat until all els. moved
  30. DEC_CNT:  POP       DI             ;Decrease el. count by 1
  31.       DEC        WORD PTR ES:[DI]
  32.       POP        BX             ;Restore contents of BX
  33.       RET                 ; and exit
  34. DEL_UL    ENDP
  35. OUR_CODE  ENDS
  36.          END       DEL_UL
  37.